/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package norepeatrandom;

import java.util.Random;

/**
 *
 * @author Abahe
 */
public class Main {

    public static void main(String[] args) {
        //Delcare new Random object
        Random rand = new Random();

        //Intialize variables
        int JUM = 40;
        int number, nRCount = 0;
        int[] array = new int[JUM];
        boolean fill;
        int RANGE = 40;

        do {
            fill = true;
            //Get new random number
            number = rand.nextInt(RANGE) + 1;
            //number = rand.nextInt(MAX);

            //If the number exists in the array already, don't add it again
            for (int i = 0; i < array.length; i++) {
                if (array[i] == number) {
                    fill = false;
                }
            }
            //If the number didn't already exist, put it in the array and move
            //To the next position.
            if (fill == true) {
                array[nRCount] = number;
                nRCount++;
            }
        } while (nRCount < JUM);
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]-1 + " ");
        }
    }
}
